package com.ficus.road.maintain.core.model.smartnew;

import com.ficus.road.maintain.core.model.Coordinate;
import com.google.common.base.Joiner;
import lombok.Data;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.data.annotation.Id;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Data
public class PrimaryRoadSectionDTO {
    @Id
    private String id;
    //唯一ID
    private String roadId;
    //道路编码
    private String roadCode;
    //道路名称
    private String roadName;
    // "起点桩号
    private Double startStake;
    // "止点桩号
    private Double endStake;
    private Double width;
    // "道路长度（km）
    private Double length;
    // "养护面积（㎡）
    private Double area;
    //道路等级
    private String level;
    //道路类型
    private String roadType;
    //高德坐标系
    private String gdzb;
    private List<Coordinate> coordinates;
    //道路类型
    private String roadCharacter;
    //需求来源
    private String source;
    // "上一次大中修时间", type = CellType.NUMERIC)
    private Double lastOverhaulYear;
    //用于排序
    private int order;
    //告警数量
    private float damagedArea;
    private List<String> hitIds;
    private Map<String, Integer> typeCount;
    private float score;
    private String hitRoad;

    public PrimaryRoadSectionDTO() {
    }

    public void generalRoadId() {
        if (ObjectUtils.isEmpty(this.roadName) || ObjectUtils.isEmpty(ObjectUtils.isEmpty(this.startStake) || ObjectUtils.isEmpty(this.endStake))) {
            return;
        }
        List<String> list = Arrays.asList(this.roadName, Double.toString(this.startStake), Double.toString(this.endStake));
        Joiner joiner = Joiner.on("_");
        this.id = joiner.join(list);
    }

    public static PrimaryRoadSectionDTO completeAttr(PrimaryRoadSectionDTO vo) {
        // area
        Double length = vo.getLength();
        if (ObjectUtils.isNotEmpty(length)) {
            vo.setArea(length * 3.75 * 1000);
        }
        // order weight
        if (ObjectUtils.isNotEmpty(vo.getSource())) {
            switch (vo.getSource()) {
                case "重点区域":
                    vo.setOrder(1);
                    break;
                case "街镇需求":
                    vo.setOrder(2);
                    break;
                case "路况需求":
                    vo.setOrder(3);
                    break;
                default:
                    vo.setOrder(4);
                    break;
            }
        } else {
            vo.setOrder(4);
        }
        return vo;
    }
}
